Last updated: 2025-02-11

Checks: 7 0

Knit directory: LSCI_pipeline/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20240916) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 2a9484f. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/1kgp/
    Ignored:    data/hgdp/
    Ignored:    data/reference/
    Ignored:    output/controls/
    Ignored:    output/figs/
    Ignored:    output/single_pos/
    Ignored:    output/single_pos_cc/
    Ignored:    output/singletons/
    Ignored:    output/slurm/
    Ignored:    output/three_pos/
    Ignored:    output/two_pos/
    Ignored:    scratch/

Untracked files:
    Untracked:  analysis/tvd_other_metrics.Rmd

Unstaged changes:
    Modified:   README.md
    Modified:   code/batch_c_v_c.sh
    Modified:   code/batch_single_pos.sh
    Modified:   code/batch_single_pos_stat.sh
    Modified:   code/sample_control.py
    Modified:   code/single_position_models.py
    Modified:   code/single_position_models_posOnly.py
    Modified:   code/sp_control_v_control.py
    Modified:   code/sp_control_v_control_v2.py
    Modified:   code/two_position_model.py
    Modified:   code/two_position_resid.py

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/three_pos_results.Rmd) and HTML (docs/three_pos_results.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 2a9484f Andy Beck 2025-02-11 wflow_publish("analysis/three_pos_results.Rmd")
html 05d7220 Andy Beck 2025-02-04 Build site.
Rmd 952e1b7 Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html b1d3781 Andy Beck 2025-02-04 Build site.
Rmd eb7a9fa Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html 60bf24e Andy Beck 2025-02-04 Build site.
Rmd 4d83939 Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html da5bf38 Andy Beck 2025-02-04 Build site.
Rmd fed7f04 Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html ee982ca Andy Beck 2025-02-04 Build site.
Rmd 4edf50d Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html 38e6b51 Andy Beck 2025-02-04 Build site.
Rmd 1311496 Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html c9e1d17 Andy Beck 2025-02-04 Build site.
Rmd 4221d4d Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html 1202a38 Andy Beck 2025-02-04 Build site.
Rmd 7f0e856 Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html 33ee2c6 Andy Beck 2025-02-04 Build site.
Rmd 1c3ffad Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html 5cc8ef4 Andy Beck 2025-02-04 Build site.
Rmd f2cfb8d Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html 24d3bdf Andy Beck 2025-02-04 Build site.
Rmd 603fb4a Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html a5d0c43 Andy Beck 2025-02-04 Build site.
Rmd 6904a6e Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")
html e19e401 Andy Beck 2025-02-04 Build site.
Rmd 853231a Andy Beck 2025-02-04 wflow_publish("analysis/three_pos_results.Rmd")

In this document we will evaluate the results from three-way interaction models. Our primary interest is contrasting their strength to single-position and two-way interactions.

Setup

Libraries

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggpubfigs) # functions for color blind friendly palettes

Attaching package: 'ggpubfigs'

The following object is masked from 'package:ggplot2':

    theme_grey
library(reactable)

Paths

base_dir <- "output" 
three_dir <- paste0(base_dir, "/three_pos") # template: base_dir/three_pos/{population}/{subtype}.csv
two_dir <- paste0(base_dir, "/two_pos") # template: base_dir/two_pos/{population}/{subtype}.csv
single_dir <- paste0(base_dir, "/single_pos") # template: base_dir/single_pos/{population}/{subtype}.csv

Data Reading

subtypes <- c("AT_CG", "AT_GC", "AT_TA",
            "GC_AT", "GC_TA", "GC_CG",
            "cpg_GC_AT", "cpg_GC_TA", "cpg_GC_CG")

read_single <- function(res_dir, pop, subtype, tp=FALSE){
  
  f_name <- paste0(res_dir, "/", pop, "/", subtype, ".csv")
  if(tp){
    return(read_csv(f_name, show_col_types = F, col_names = c("dev","singletons","controls","rp1","rp2")))
  }
  return(read_csv(f_name, show_col_types = FALSE))
}

read_all <- function(single_dir, two_dir, three_dir, pop, subtype){
  s_df <- read_single(single_dir, pop, subtype)
  two_df <- read_single(two_dir, pop, subtype, tp=T)
  three_df <- read_single(three_dir, pop, subtype)
  
  # compute re 
  three_df <- three_df %>%
    mutate(re = dev / (2 * (singletons + controls)))
  two_df <- two_df %>%
    mutate(re = dev / (2 * (singletons + controls)))
  s_df <- s_df %>%
    mutate(re = dev / (2 * (singletons + controls)))
  
  # rank by re
  three_df <- three_df %>%
    mutate(class_rank = dense_rank(desc(re)))
  two_df <- two_df %>%
    mutate(class_rank = dense_rank(desc(re)))
  s_df <- s_df %>%
    mutate(class_rank = dense_rank(desc(re)))
  
  # unify structure: dev, offsets, re, class, class_rank
  three_df <- three_df %>%
    rowwise() %>%
    mutate(offset = paste0(rp1, "_", rp2, "_", rp3)) %>%
    ungroup() %>%
    mutate(class = "3-pos") %>%
    select(dev, offset, re, class ,class_rank) 
  
  two_df <- two_df %>%
    mutate(class = "2-pos") %>%
    rowwise() %>%
    mutate(offset = paste0(rp1, "_", rp2)) %>%
    ungroup() %>%
    select(dev, offset, re, class, class_rank)
  
  s_df <- s_df %>%
    mutate(class = "1-pos",
           offset = as.character(offset)) %>%
    select(dev, offset, re, class, class_rank)
  
  final_df <- bind_rows(s_df, two_df, three_df)
  return(final_df)
}

Rank Plots

subtype_print_names <- function(st){
  if(str_starts(st, "AT")){
    return(paste0("A → ", str_sub(st, 4, 4)))
  } else if(str_starts(st, "GC")){
    return(paste0("C → ", str_sub(st, 5, 5)))
  } else{
    return(paste0("CpG → ", str_sub(st, 9, 9), "pG"))
  }
}

# function will print both table and plot
plot_ranked_re <- function(single_dir, two_dir, three_dir, pop, subtype, rank_lim = 20){
  df <- read_all(single_dir, two_dir, three_dir, pop, subtype)
  
  max_re <- max(df$re)
  df$pct_max <- df$re / max_re
  
  p <- df %>%
    filter(class_rank <= rank_lim) %>%
    mutate(class2 = recode(class, "1-pos" = "Single", "2-pos" = "Two-Way", "3-pos" = "Three-Way")) %>%
    ggplot(aes(x = class_rank, y = pct_max, colour = class2, shape = class2)) +
    geom_point(size = 2.5) +
    scale_colour_manual(values=friendly_pal("contrast_three"), name = "Type", breaks=c("Single","Two-Way","Three-Way")) +
    scale_shape_discrete(name = "Type", breaks=c("Single","Two-Way","Three-Way")) +
    theme_classic(base_size = 12, base_family = "Helvetica") +
    theme(legend.position = "inside",
          legend.position.inside = c(.8, .8)) +
    ylab("% of Max RE") +
    xlab(paste0("Within-class Rank: ", subtype_print_names(subtype)))
  return(list(df=df, fig=p))
}

Figures and Tables

Let’s look at mtcars instead of local sequence context non-sense…

reactable(mtcars[1:4, 1:5])

And now that the reactable stuff has been attached to our document, let’s look at local sequence context results :)

ALL

AT_CG

Version Author Date
60bf24e Andy Beck 2025-02-04

AT_GC

Version Author Date
60bf24e Andy Beck 2025-02-04

AT_TA

Version Author Date
60bf24e Andy Beck 2025-02-04

GC_AT

Version Author Date
60bf24e Andy Beck 2025-02-04

GC_TA

Version Author Date
60bf24e Andy Beck 2025-02-04

GC_CG

Version Author Date
60bf24e Andy Beck 2025-02-04

cpg_GC_AT

Version Author Date
60bf24e Andy Beck 2025-02-04

cpg_GC_TA

Version Author Date
60bf24e Andy Beck 2025-02-04

cpg_GC_CG

Version Author Date
60bf24e Andy Beck 2025-02-04

AFR

AT_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_GC

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

AMR

AT_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_GC

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

EAS

AT_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_GC

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

EUR

AT_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_GC

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

SAS

AT_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_GC

Version Author Date
05d7220 Andy Beck 2025-02-04

AT_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_AT

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_TA

Version Author Date
05d7220 Andy Beck 2025-02-04

cpg_GC_CG

Version Author Date
05d7220 Andy Beck 2025-02-04

sessionInfo()
R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3;  LAPACK version 3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/New_York
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] reactable_0.4.4 ggpubfigs_0.0.1 lubridate_1.9.3 forcats_1.0.0  
 [5] stringr_1.5.1   dplyr_1.1.4     purrr_1.0.2     readr_2.1.5    
 [9] tidyr_1.3.1     tibble_3.2.1    ggplot2_3.5.1   tidyverse_2.0.0
[13] workflowr_1.7.1

loaded via a namespace (and not attached):
 [1] gtable_0.3.6      xfun_0.49         bslib_0.8.0       htmlwidgets_1.6.4
 [5] processx_3.8.4    callr_3.7.6       tzdb_0.4.0        vctrs_0.6.5      
 [9] tools_4.4.2       crosstalk_1.2.1   ps_1.8.1          generics_0.1.3   
[13] parallel_4.4.2    fansi_1.0.6       pkgconfig_2.0.3   lifecycle_1.0.4  
[17] farver_2.1.2      compiler_4.4.2    git2r_0.33.0      munsell_0.5.1    
[21] getPass_0.2-4     httpuv_1.6.15     htmltools_0.5.8.1 sass_0.4.9       
[25] yaml_2.3.10       later_1.3.2       pillar_1.9.0      crayon_1.5.3     
[29] jquerylib_0.1.4   whisker_0.4.1     cachem_1.1.0      tidyselect_1.2.1 
[33] digest_0.6.37     stringi_1.8.4     labeling_0.4.3    rprojroot_2.0.4  
[37] fastmap_1.2.0     grid_4.4.2        archive_1.1.8     colorspace_2.1-1 
[41] cli_3.6.3         magrittr_2.0.3    utf8_1.2.4        withr_3.0.2      
[45] reactR_0.6.1      scales_1.3.0      promises_1.3.0    bit64_4.6.0-1    
[49] timechange_0.3.0  rmarkdown_2.29    httr_1.4.7        bit_4.5.0.1      
[53] hms_1.1.3         evaluate_1.0.1    knitr_1.49        rlang_1.1.4      
[57] Rcpp_1.0.13-1     glue_1.8.0        rstudioapi_0.17.1 vroom_1.6.5      
[61] jsonlite_1.8.9    R6_2.5.1          fs_1.6.5